
/**
 *
 * @author Xinchro
 */
import java.awt.Dimension;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.event.*;
import java.awt.*;
import java.awt.Window;
import javax.swing.*;
import java.awt.ScrollPane;

public class RSSGUI{

    JFrame frame;
    JTextArea txtArea;
    JScrollPane scrollPane;
    List list;
    GridLayout grid;

    public RSSGUI(RSSFeed rssFeed) {
        grid = new GridLayout();
        txtArea = new JTextArea();
        //txtArea.setSize(300, 200);
        txtArea.setEditable(false);
        //txtArea.setMaximumSize(new Dimension(300, 200));
        txtArea.setLineWrap(true);
        scrollPane = new JScrollPane(txtArea);
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        
        txtArea.addKeyListener(rssFeed.input);
        txtArea.addMouseListener(rssFeed.input);
        txtArea.addMouseWheelListener(rssFeed.input);
        scrollPane.addKeyListener(rssFeed.input);
        scrollPane.addMouseListener(rssFeed.input);
        scrollPane.addMouseWheelListener(rssFeed.input);
        
        
        list = new List();
        list.setName("URLList");
        list.add("http://feeds.gawker.com/lifehacker/full");
        list.add("http://feeds.feedburner.com/nerfnow/full");
        list.add("http://www.guildwars2.com/en/rss.xml");
        list.addKeyListener(rssFeed.input);
        list.addMouseListener(rssFeed.input);
        list.addMouseWheelListener(rssFeed.input);

        frame = new JFrame();
        frame.setTitle("RSS Reader");
        frame.setSize(800, 600);
        frame.addKeyListener(rssFeed.input);
        frame.addMouseListener(rssFeed.input);
        frame.addMouseWheelListener(rssFeed.input);
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        //frame.add(txtArea);
        //scrollPane.setSize(100, 100);
        scrollPane.setSize(600, 600);
        //scrollPane.setBounds(0, 0, 600, 600);
        //Dimension dim1 = new Dimension(600,600);
        //scrollPane.setMaximumSize(dim1);
        frame.add(scrollPane);
        frame.add(list);
        grid.setRows(1);
        grid.setColumns(2);
        frame.setLayout(grid);
        
        list.setSize(50, 600);
        //list.setMaximumSize(dim1);
        //list.setLocation(frame.getWidth()-list.getWidth(), 0);
        //list.setBounds(frame.getWidth()-list.getWidth(), 0, 100, 600);
        

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        int w = frame.getSize().width;
        int h = frame.getSize().height;
        int x = (dim.width - w) / 2;
        int y = (dim.height - h) / 2;

        frame.setLocation(x, y);
        frame.setFocusable(true);
        frame.addKeyListener(rssFeed.input);
        frame.addMouseListener(rssFeed.input);
        frame.addMouseWheelListener(rssFeed.input);
    }
    


    public void addText(String text) {
        txtArea.append(text);
    }
    
    public void setText(String text){
        txtArea.setText(text);
    }
}
